package com.meixiang.fragment.fund;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.meixiang.R;
import com.meixiang.activity.account.myfund.FundDetialActivity;
import com.meixiang.activity.account.myfund.MyFundActivity;
import com.meixiang.adapter.myFundAdapter.FundOptionalAdapter;
import com.meixiang.adapter.myFundAdapter.FundOptionalSortAdapter;
import com.meixiang.dialog.OptionalScreenPopup;
import com.meixiang.entity.fund.FundOptionalBean;
import com.meixiang.main.BaseFragment;
import com.meixiang.recyclerview.OnStartDragListener;
import com.meixiang.recyclerview.SimpleItemTouchHelperCallback;
import com.meixiang.tool.Tool;
import com.meixiang.util.DensityUtil;
import com.meixiang.view.swipetoloadlayout.base.SwipeToLoadLayout;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 自选基金 ----编辑页
 * Created by xyj on 2016/5/31.
 */
public class OptionalSortFragment extends BaseFragment implements OnStartDragListener{

    @Bind(R.id.swipe_target)
    RecyclerView swipe_target ;
    View rootView ;
    private ItemTouchHelper mItemTouchHelper;
    private static ArrayList<FundOptionalBean> fund_select_list ;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(getArguments()!=null){
            fund_select_list = getArguments().getParcelableArrayList("optionList");
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        rootView = inflater.inflate(R.layout.fragment_optional_sort_content, container, false);
        ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
            FundOptionalSortAdapter adapter = new FundOptionalSortAdapter(this,fund_select_list);
            swipe_target.setAdapter(adapter);
            swipe_target.setLayoutManager(new LinearLayoutManager(getActivity()));
            swipe_target.setHasFixedSize(true);
            //声明ItemTouchHelper，并绑定到待管理的RecyclerView上
            ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(adapter);
            mItemTouchHelper = new ItemTouchHelper(callback);
            mItemTouchHelper.attachToRecyclerView(swipe_target);
    }

    public static ArrayList<FundOptionalBean> getOptionList() {
        return fund_select_list;
    }

    @Override
    protected void initTitle() {

    }

    @Override
    protected void initView() {
    }

    @Override
    protected void setData() {

    }

    public static OptionalSortFragment getIntance(Bundle bundle){
        OptionalSortFragment optionalSortFragment = new OptionalSortFragment();
        optionalSortFragment.setArguments(bundle);
        return optionalSortFragment;
    }

    @Override
    public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
        mItemTouchHelper.startDrag(viewHolder);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

}
